from django.http import HttpRequest, HttpResponse, JsonResponse
from django.shortcuts import render

from DashBoard.models import DataInfo, GeoInfo

# Create your views here.
def DB_index(request):
    dataObjs = DataInfo.objects.all()
    dataList = []
    # print(data)
    for item in dataObjs:
        content_data = {}
        content_data['name'] = item.place.name
        content_data['value'] = float(item.data)
        dataList.append(content_data)

    geoObjects = GeoInfo.objects.all()
    geoList = []

    for item in geoObjects:
        content_geo = {}
        content_geo['name'] = item.name 
        content_geo['lle'] = [float(item.longitude), float(item.latitude), float(item.elevation)]
        geoList.append(content_geo)
    print(geoList)

    return render(request, 'index.html', {"data_nv": dataList, "data_geo": geoList})

def DB_list(request):
    pass

# get不带参数
def indexApi_get(request):
    dataObjs = DataInfo.objects.all()
    dataList = []
    # print(data)
    for item in dataObjs:
        content_data = {}
        content_data['name'] = item.place.name
        content_data['value'] = float(item.data)
        dataList.append(content_data)

    return JsonResponse({'code':200,'msg':'这是后端jsonresponse','data':dataList})